﻿
using Prometheus.Binding.Core;
using Prometheus.Binding.ReadOnly;
using Prometheus.Binding.Validation;


#if NETFX_CORE || UNIVERSAL
using Windows.UI.Xaml;
#else
using System.Windows;
#endif
namespace Prometheus.Binding
{
    /// <summary>
    /// Use this control to host another controls with prometheus binding
    /// </summary>
    public class proForm : proValidationForm
    {
#if WINDOWS_PHONE
        /// <summary>
        /// Binds the control property to any path from datacontext
        /// </summary>
        public static readonly DependencyProperty proBindingProperty = DependencyProperty.RegisterAttached("proBinding",
                                                                                                           typeof (
                                                                                                               proBindingBase
                                                                                                               ),
                                                                                                           typeof (
                                                                                                               proForm
                                                                                                               ),
                                                                                                           new PropertyMetadata
                                                                                                               (null,
                                                                                                                proBindingChanged));

        private static void proBindingChanged(DependencyObject dependencyObject,
                                              DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
        {
            SetproBinding((FrameworkElement) dependencyObject,
                          (proBindingBase) dependencyPropertyChangedEventArgs.NewValue);
        }
#endif

        /// <summary>
        /// Initialize the binding for the element
        /// </summary>
        public new static void SetproBinding(FrameworkElement element, proBindingBase bindingBase)
        {
            proReadOnlyForm.SetproBinding(element, bindingBase);
        }

        /// <summary>
        /// Get first binding for the element
        /// </summary>
        public new static proBindingBase GetproBinding(FrameworkElement element)
        {
            return proReadOnlyForm.GetproBinding(element);
        }

        /// <summary>
        /// Get all bindings which belong to provided element
        /// </summary>
        public new static proBindingBase[] GetBindingsByElement(UIElement element)
        {
            return proFormBase.GetBindingsByElement(element);
        }
    }
}